package com.book.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.book.entity.Book;
import com.book.service.ManagerService;


/**
 * Servlet implementation class ManagerUpdateBook2
 */
@WebServlet("/ManagerUpdateBook2")
public class ManagerUpdateBook2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ManagerUpdateBook2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取修改页面的请求参数，然后调用业务逻辑层对象，实现最终修改
				request.setCharacterEncoding("UTF-8");
				response.setCharacterEncoding("UTF-8");
				response.setContentType("text/html; charset=UTF-8");
				String book_id = request.getParameter("book_id");
				String book_name =request.getParameter("book_name");
				String author =request.getParameter("author");
				String press = request.getParameter("press");
				
				
				Book b=new Book(book_id, book_name, author, press);
				ManagerService ms=new ManagerService();
				boolean result=ms.updateBook(b);
				System.out.println(b);
				System.out.println(result);
				if(result){
					request.getRequestDispatcher("ManagerSelectBook").forward(request, response);
				}else{
					response.sendRedirect("update.jsp");
				}
				
			}

	}


